package com.iyundao.io.mapper;

import com.iyundao.io.model.ActivityModelLookBack;
import com.iyundao.io.tools.ActivityModelVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ActivityModelLookBackMapper {
    @Insert({
        "insert into activitymodellookback (id, activitytitle, ",
        "activitycontent, activitystarttime, ",
        "activityendtime, activitysignstarttime, ",
        "activitysignendtime, activitylongitude, ",
        "activitylatitude, activitysitename, ",
        "activitycreatetime, activitynumber, ",
        "activityjoinnumber, activityintegral, ",
        "activityimg, userid, ",
        "activityflag, activityid, ",
        "activitydigest, organizationid)",
        "values (#{id,jdbcType=INTEGER}, #{activitytitle,jdbcType=VARCHAR}, ",
        "#{activitycontent,jdbcType=VARCHAR}, #{activitystarttime,jdbcType=TIMESTAMP}, ",
        "#{activityendtime,jdbcType=TIMESTAMP}, #{activitysignstarttime,jdbcType=TIMESTAMP}, ",
        "#{activitysignendtime,jdbcType=TIMESTAMP}, #{activitylongitude,jdbcType=DOUBLE}, ",
        "#{activitylatitude,jdbcType=DOUBLE}, #{activitysitename,jdbcType=VARCHAR}, ",
        "#{activitycreatetime,jdbcType=TIMESTAMP}, #{activitynumber,jdbcType=INTEGER}, ",
        "#{activityjoinnumber,jdbcType=INTEGER}, #{activityintegral,jdbcType=INTEGER}, ",
        "#{activityimg,jdbcType=VARCHAR}, #{userid,jdbcType=VARCHAR}, ",
        "#{activityflag,jdbcType=INTEGER}, #{activityid,jdbcType=INTEGER}, ",
        "#{activitydigest,jdbcType=VARCHAR}, #{organizationid,jdbcType=VARCHAR})"
    })
    int insert(ActivityModelLookBack record);

    @InsertProvider(type=ActivityModelLookBackSqlProvider.class, method="insertSelective")
    int insertSelective(ActivityModelLookBack record);

    @Select("select a.id, a.activitytitle,a.activitycontent,DATE_FORMAT(a.activitystarttime,'%Y-%m-%d %H:%i:%s') activitystarttime,DATE_FORMAT(a.activityendtime,'%Y-%m-%d %H:%i:%s') activityendtime, " +
            "DATE_FORMAT(a.activitysignstarttime,'%Y-%m-%d %H:%i:%s') activitysignstarttime, DATE_FORMAT(a.activitysignendtime,'%Y-%m-%d %H:%i:%s') activitysignendtime, a.activitylongitude, a.activitylatitude, " +
            "a.activitysitename, DATE_FORMAT(a.activitycreatetime,'%Y-%m-%d %H:%i:%s') activitycreatetime, a.activitynumber, a.activityjoinnumber, a.activityintegral, " +
            "a.activityimg, a.userid, a.activityflag, a.activityid, a.activitydigest, a.organizationid,ac.categoryname,ac.categoryintegral" +
            " from activitymodel a " +
            "INNER JOIN activitycategory ac " +
            " on a.activityid= ac.id ")
    List<ActivityModelVo> selectAll();

    @Update("update activitymodellookback set activityflag=1 where id=(#{id,jdbcType=INTEGER}")
    int updateFlag(Integer id);
}